package com.zhilianbao.leyaogo.ui.activity.me.setting;

import android.os.Bundle;
import android.text.Editable;
import android.widget.EditText;
import android.widget.TextView;

import com.bql.utils.CheckUtils;
import com.zhilianbao.leyaogo.R;
import com.zhilianbao.leyaogo.http.api.AccountApi;
import com.zhilianbao.leyaogo.http.callback.DialogCallback;
import com.zhilianbao.leyaogo.ui.activity.base.BaseOkHttpActivity;
import com.zhilianbao.leyaogo.utils.Utils;
import com.zhilianbao.leyaogo.utils.XToastUtils;
import com.zhilianbao.leyaogo.view.widgets.AwesomeEditTextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;

/**
 * 意见反馈
 */
public class IdeaBackActivity extends BaseOkHttpActivity {

    @BindView(R.id.your_idea)
    AwesomeEditTextView mYourIdea;
    @BindView(R.id.your_connect_num)
    EditText mYourConnectNum;
    @BindView(R.id.tv_idea_commit)
    TextView tvIdeaCommit;

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_idea_back;
    }

    @Override
    protected void initViewsAndEvents(Bundle savedInstanceState) {
        initToolbar(getString(R.string.idea_back));
        initEditText();
        mYourConnectNum.setText(Utils.getUserLoginInfo().getUserMobile());
        mYourConnectNum.setEnabled(false);
    }

    private void initEditText() {
        //设置光标停留在最后
        Editable idea = mYourIdea.getText();
        mYourIdea.setSelection(idea.length());
        Editable num = mYourConnectNum.getText();
        mYourConnectNum.setSelection(num.length());
        mYourIdea.setFilterEmoji(true);
    }

    @OnClick(R.id.tv_idea_commit)
    public void onClick() {
        String opinionsContent = mYourIdea.getText().toString().trim();
        if (CheckUtils.isEmpty(opinionsContent)) {
            XToastUtils.showShortToast("意见内容不能为空");
        } else {
            AccountApi.ideaBack(this, Utils.getUserLoginInfo().getUserId(), opinionsContent, null, new DialogCallback<Object>(this, "意见提交中,请稍后") {
                @Override
                public void onSuccess(Object o, Call call, Response response) {
                    XToastUtils.showShortToast("意见提交成功");
                    mYourIdea.setText("");
                }
            });
        }
    }
}
